<template>
  <div>
    <el-form :model="form" label-width="80px">
      <el-form-item label="车辆名称">
        <el-input v-model="form.name"></el-input>
        <el-select v-model="form.user">
          <el-option v-for="item in usernameItem" :key="item._id" :label="item.name" :value="item._id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-button @click="submit" type="primary">提交</el-button>
    <el-button @click="fetch" type="primary">获取</el-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        name:"",
        user: "",
      },
      usernameItem: []
    }
  },
  methods: {
    async submit() {
      (!!this.form.name && !!this.form.user) && await this.$http.post("/car",this.form)
    },
    async fetch() {
      await this.$http.get("/car");
    }
  },
  async created() {
    const res = await this.$http.get("/user")
    this.usernameItem = res.data.data
    console.log(this.usernameItem)
  }
}
</script>
